package top.hhydra.mimall.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;
import top.hhydra.mimall.constant.MallConst;
import top.hhydra.mimall.entity.User;
import top.hhydra.mimall.exception.UserLoginException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Description
 * @auther SaiyeEmon
 * @create 2020-02-11 1:20
 */
@Slf4j
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.info("==LoginInterceptor--preHandle==");
        User user = (User)request.getSession().getAttribute(MallConst.CURRENT_USER);
        if(user == null){
            throw new UserLoginException();
        }
        return true;
    }
}
